package com.wzy.business.store.main

import android.app.Activity
import android.content.Intent
import com.wangzhenyu.common.base.BaseVBPActivity
import com.wzy.business.databinding.ActivityApplyShopHintBinding
import com.wzy.business.store.main.bean.ApplyShopHint
import com.wzy.business.store.main.presenter.ApplyShopHintPresenter
import com.wzy.business.store.main.presenter.impl.ApplyShopHintPresenterImpl

class ApplyShopHintActivity :
    BaseVBPActivity<ActivityApplyShopHintBinding, ApplyShopHintPresenter>(),
    ApplyShopHintPresenter.View {

    companion object {
        private const val REQUEST_CODE_SERVICE = 8
    }

    override fun useLightMode() = false

    override fun getViewBinding() = ActivityApplyShopHintBinding.inflate(layoutInflater)

    override fun createPresenter() = ApplyShopHintPresenterImpl(this, this)

    override fun initView() {
        mToolBarDelegate?.setMidTitle("申请开店")

        mBinding.apply {


            ivApplyShopHintNext.isSelected = true


            ivApplyShopHintNext.setOnClickListener {
                ivApplyShopHintNext.isSelected = !ivApplyShopHintNext.isSelected
            }

            tvApplyShopHintService.setOnClickListener {
                val intent = Intent(this@ApplyShopHintActivity, UserServiceH5Activity::class.java)
                startActivityForResult(intent, REQUEST_CODE_SERVICE)
            }

            tvApplyShopHintNext.setOnClickListener {
                if (!ivApplyShopHintNext.isSelected) {
                    showToast("请先同意商城入驻协议")
                    return@setOnClickListener
                }
                ApplyShopInfoActivity.openActivity(this@ApplyShopHintActivity, false)
                finish()
            }
        }


    }

    override fun onApplyShopHintSuccess(bean: ApplyShopHint) {
        hidePageLoading()
    }

    override fun onApplyShopHintError(code: Int) {
        hidePageLoading()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == REQUEST_CODE_SERVICE && resultCode == Activity.RESULT_OK) {
            mBinding.ivApplyShopHintNext.isSelected = true
        }
    }
}